/**
 * Copyright 2011 Google Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
package com.google.solarchallenge.shared.dtos;

import com.google.solarchallenge.shared.ApplicationStatus;
import com.google.solarchallenge.shared.DocumentStatus;

import java.util.ArrayList;

/**
 * DTO for Application.
 *
 * @author Arjun Satyapal
 */
public class ApplicationDto implements AbstractDto {
  private ApplicationDto() {
  }

  // TODO : This can get bulky if there are too many files but puting
  // for the time being.
  private Long id;
  private String applicationDetails;
  private ApplicationStatus overallApplicationStatus;
  private ArrayList<String> siteDiagramUrls;
  private DocumentStatus siteDiagramStatus;
  private ArrayList<String> electricalDiagramUrls;
  private DocumentStatus electricalDiagramStatus;
  private ArrayList<String> diagramNoteUrls;
  private DocumentStatus diagramNoteStatus;

  @Override
  public StringBuilder getStringBuilder() {
    StringBuilder builder = new StringBuilder();
    builder.append("SiteDiagram : Status[")
        .append(siteDiagramStatus)
        .append("], Urls : {");
    for (String currUrl : siteDiagramUrls) {
      builder.append("[").append(currUrl).append("], ");
    }

    builder.append("\nElectricalDiagram : Status[")
        .append(electricalDiagramStatus)
        .append("], Urls : {");
    for (String currUrl : electricalDiagramUrls) {
      builder.append("[").append(currUrl).append("], ");
    }

    builder.append("\nDiagramNotes : Status[")
        .append(diagramNoteStatus)
        .append("], Urls : {");
    for (String currUrl : diagramNoteUrls) {
      builder.append("[").append(currUrl).append("], ");
    }

    return builder;
  }

  @Override
  public String toString() {
    return getStringBuilder().toString();
  }



  public String getId() {
    return Long.toString(id);
  }

  public ArrayList<String> getSiteDiagramUrls() {
    return siteDiagramUrls;
  }

  public DocumentStatus getSiteDiagramStatus() {
    return siteDiagramStatus;
  }

  public ArrayList<String> getElectricalDiagramUrls() {
    return electricalDiagramUrls;
  }

  public DocumentStatus getElectricalDiagramStatus() {
    return electricalDiagramStatus;
  }

  public ArrayList<String> getDiagramNoteUrls() {
    return diagramNoteUrls;
  }

  public DocumentStatus getDiagramNoteStatus() {
    return diagramNoteStatus;
  }


  public String getApplicationDetails() {
    return applicationDetails;
  }

  public ApplicationStatus getOverallApplicationStatus() {
    return overallApplicationStatus;
  }

  public static class Builder {
    private Long id;
    private String applicationDetails;
    private ApplicationStatus overallApplicationStatus;
    private ArrayList<String> siteDiagramUrls;
    private DocumentStatus siteDiagramStatus;
    private ArrayList<String> electricalDiagramUrls;
    private DocumentStatus electricalDiagramStatus;
    private ArrayList<String> diagramNoteUrls;
    private DocumentStatus diagramNoteStatus;

    public Builder setId(Long id) {
      this.id = id;
      return this;
    }

    public Builder setApplicationDetails(String applicationDetails) {
      this.applicationDetails = applicationDetails;
      return this;
    }

    public Builder setOverallApplicationDetails(
        ApplicationStatus overallApplicationStatus) {
      this.overallApplicationStatus = overallApplicationStatus;
      return this;
    }

    public Builder setSiteDiagramUrls(ArrayList<String> siteDiagramUrls) {
      this.siteDiagramUrls = siteDiagramUrls;
      return this;
    }

    public Builder setSiteDiagramStatus(DocumentStatus siteDiagramStatus) {
      this.siteDiagramStatus = siteDiagramStatus;
      return this;
    }

    public Builder setElectricalDiagramUrls(
        ArrayList<String> electricalDiagramUrls) {
      this.electricalDiagramUrls = electricalDiagramUrls;
      return this;
    }

    public Builder setElectricalDiagramStatus(
        DocumentStatus electricalDiagramStatus) {
      this.electricalDiagramStatus = electricalDiagramStatus;
      return this;
    }

    public Builder setDiagramNoteUrls(ArrayList<String> diagramNoteUrls) {
      this.diagramNoteUrls = diagramNoteUrls;
      return this;
    }

    public Builder setDiagramNoteStatus(DocumentStatus diagramNoteStatus) {
      this.diagramNoteStatus = diagramNoteStatus;
      return this;
    }

    public ApplicationDto build() {
      ApplicationDto dto = new ApplicationDto();
      dto.id = id;
      dto.applicationDetails = applicationDetails;
      dto.overallApplicationStatus = overallApplicationStatus;
      dto.siteDiagramUrls = new ArrayList<String>(siteDiagramUrls);
      dto.siteDiagramStatus = siteDiagramStatus;
      dto.electricalDiagramUrls = new ArrayList<String>(electricalDiagramUrls);
      dto.electricalDiagramStatus = electricalDiagramStatus;
      dto.diagramNoteUrls = new ArrayList<String>(diagramNoteUrls);
      dto.diagramNoteStatus = diagramNoteStatus;
      return dto;
    }
  }

  @Override
  public String validate() {
    // Nothing to validate as all information is coming from server side.
    return null;
  }
}
